<template>
  <div>
    CalculationYear
    <div>第一种计算方式：开始时间给时间戳</div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="活动名称">
        <el-input v-model="form.year" style="width: 200px"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import dayjs from "dayjs";
export default {
  data() {
    return {
      form: {
        startDate: 1589972068000,
        year: "1",
      },
    };
  },
  methods: {},
  created() {
    const date = dayjs(new Date());
    // dayjs里面的diff方法用来计算时间差
    let chayear = date.diff(this.form.startDate, "month");
    console.log(chayear, "chayear");

    const year = Math.floor(chayear / 12);
    this.form.year = year;
  },
};
</script>
<style scoped></style>
